package com.eleventwelve.iris.persistence.evolve;

import java.util.ArrayList;
import java.util.List;

import org.opentides.bean.DynamicReport;
import org.opentides.bean.SystemCodes;
import org.opentides.persistence.SystemCodesDAO;
import org.opentides.persistence.evolve.DBEvolve;
import org.opentides.persistence.evolve.Evolver;
import org.opentides.service.ReportService;

/**
 * 
 * @author Ashley
 *
 */
public class DBEvolve003 extends Evolver implements DBEvolve {
	private SystemCodesDAO systemCodesDAO;
	
	private ReportService reportService;
	
	private String jasperPath;
	
	@Override
	public void execute() {
		List<SystemCodes> systemCodes = new ArrayList<SystemCodes>();
		systemCodes.addAll(prepareStafftypes());
		systemCodes.addAll(prepareResultStatus());
		systemCodesDAO.saveAllEntityModel(systemCodes);
		
		saveReport("PATIENT_SUMMARY",
				"Patient Summary",
				"patient-summary",
				"patient-summary",
				"Patient Summary");
	}
	
	private List<SystemCodes> prepareResultStatus(){
		List<SystemCodes> systemCodes = new ArrayList<SystemCodes>();
		systemCodes.add(new SystemCodes("RESULT_STATUS", "NEW", "New"));
		systemCodes.add(new SystemCodes("RESULT_STATUS", "RESOLVING", "Resolving"));
		systemCodes.add(new SystemCodes("RESULT_STATUS", "RESOLVED", "Resolved"));
		systemCodes.add(new SystemCodes("RESULT_STATUS", "UNRESOLVED", "Unresolved"));
		systemCodes.add(new SystemCodes("RESULT_STATUS", "UNCOMPLIANT", "Uncompliant"));
		return systemCodes;
	}
	
	private List<SystemCodes> prepareStafftypes(){
		List<SystemCodes> systemCodes = new ArrayList<SystemCodes>();
		systemCodes.add(new SystemCodes("STAFF_TYPE", "DOCTOR", "Doctor"));
		systemCodes.add(new SystemCodes("STAFF_TYPE", "STAFF", "Staff"));
		return systemCodes;
	}
	
	private void saveReport(String accessCode, String description, String name, String reportFile, String title) {
		DynamicReport dynamicReport = new DynamicReport();
		dynamicReport.setAccessCode(accessCode);
		dynamicReport.setDescription(description);
		dynamicReport.setName(name);
		dynamicReport.setReportPath(jasperPath);
		dynamicReport.setTitle(title);
		dynamicReport.setReportFile(reportFile);
		this.reportService.save(dynamicReport);
	}
	
	@Override
	public String getDescription() {
		return new String("Added Result status and Staff types");
	}

	@Override
	public int getVersion() {
		return 3;
	}
	
	public SystemCodesDAO getSystemCodesDAO() {
		return systemCodesDAO;
	}
	
	public void setSystemCodesDAO(SystemCodesDAO systemCodesDAO) {
		this.systemCodesDAO = systemCodesDAO;
	}
	
	public void setReportService(ReportService reportService) {
		this.reportService = reportService;
	}
	
	public void setJasperPath(String jasperPath) {
		this.jasperPath = jasperPath;
	}

}
